package com.ymatou.iapi.godmch.service;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import jdk.nashorn.internal.codegen.CompilerConstants.Call;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.ymatou.iapi.godmch.parameter.PointConfig;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
*获取积分配置Call
*FreeMaker Template自动生成代码
*/
public class getPointConfigCall extends YmatouBaseCall{
	private static String opurl ="api/point/getPointConfig";
	
	public getPointConfigCall() {
		super(EnvSetup.getSystemUrl("godmch_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	
	 public String getStatusCode1()
		{
		  return getString("status");
		}
		
		 public String getMessage()
		{
		 return getString("msg");
		}
		 
		 public boolean getEnabled() throws JSONException
		{
		 return  new JSONObject(getString("result").toString()).getBoolean("enabled");
		}
		 
		 public List<PointConfig> getPointConfigList() throws JsonSyntaxException, JSONException {
			 Gson gson = new Gson();
			 List<PointConfig> pointConfigs = gson.fromJson( new JSONObject(getString("result").toString()).getJSONArray("pointConfigList").toString(),
					 new TypeToken<List<PointConfig>>() { }.getType());//对于不是类的情况，用这个参数给出
			 
			return pointConfigs;
		}
}